﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PIMS.WorkPlugin.Util.Config
{
    /// <summary>
    /// 从控件自身的配置文件取值
    /// </summary>
    internal class ConfigManager
    {
        readonly static bool _Error;

        readonly static string dllName = "Plugins\\PIMS_WorkPlugin.dll";

        static Configuration _AppConfig;

        static ConfigManager()
        {
            string dllPath = string.Format(
                "{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, dllName);

            try
            {
                _AppConfig = ConfigurationManager.OpenExeConfiguration(dllPath);
            }
            catch (ConfigurationErrorsException)
            {
                Console.WriteLine(dllPath);
                _Error = true;
            }
        }

        public static KeyValueConfigurationCollection AppSettings
        {
            get
            {
                if (_Error) return null;
                return _AppConfig.AppSettings.Settings;
            }
        }

        public static ConnectionStringSettingsCollection ConnectionStrings
        {
            get
            {
                if (_Error) return null;
                return _AppConfig.ConnectionStrings.ConnectionStrings;
            }
        }
    }
}
